export const columns = [
  {
    type: 'index',
    align: 'left',
    width: 80,
    label: '序号',
  },
  {
    label: '状态',
    prop: 'departmentStatus',
    align: 'left',
    slot: 'state',
  },
  {
    label: '部门',
    prop: 'departmentName',
    align: 'left',
  },
  {
    label: '负责人',
    prop: 'employeeName',
    align: 'left',
  },
  {
    label: '联系方式',
    prop: 'employeePhone',
    align: 'left',
  },
  {
    label: '创建时间',
    prop: 'createTimeStr',
    align: 'left',
  },
  {
    label: '操作',
    prop: 'operate',
    align: 'left',
    slot: 'operate',
  },
];

const table = {
  code: '200',
  message: '成功',
  data: {
    obtainDepartment: {
      currentPage: '1',
      totalPage: '3',
      totalEntries: '26',
      queryCriteria: '',
      pageSize: '10',
      stateFlag: null,
    },
    allDepartmentsList: [
      {
        departmentEmployeeDO: {
          departmentId: '1',
          departmentName: '市场营销部门',
          parentDepartmentId: '0',
          departmentStatus: '1',
          createTime: '2023-12-07 21:13:21',
          employeeId: '1',
          employeeName: null,
          employeePhone: null,
          employeeEmail: null,
        },
        children: [
          {
            departmentId: '2',
            departmentName: '品牌管理团队',
            parentDepartmentId: '1',
            departmentStatus: '0',
            createTime: '2023-12-07 21:30:54',
            employeeId: null,
            employeeName: null,
            employeePhone: null,
            employeeEmail: null,
          },
        ],
      },
      {
        departmentEmployeeDO: {
          departmentId: '5',
          departmentName: '行政管理部门',
          parentDepartmentId: '0',
          departmentStatus: '0',
          createTime: '2023-12-07 21:30:48',
          employeeId: null,
          employeeName: null,
          employeePhone: null,
          employeeEmail: null,
        },
        children: [
          {
            departmentId: '13',
            departmentName: '品牌管理团队',
            parentDepartmentId: '5',
            departmentStatus: null,
            createTime: null,
            employeeId: null,
            employeeName: null,
            employeePhone: null,
            employeeEmail: null,
          },
          {
            departmentId: '15',
            departmentName: '广告宣传团队',
            parentDepartmentId: '5',
            departmentStatus: null,
            createTime: null,
            employeeId: null,
            employeeName: null,
            employeePhone: null,
            employeeEmail: null,
          },
        ],
      },
      {
        departmentEmployeeDO: {
          departmentId: '6',
          departmentName: '人才发展部门',
          parentDepartmentId: '0',
          departmentStatus: '0',
          createTime: '2023-12-07 21:30:52',
          employeeId: null,
          employeeName: null,
          employeePhone: null,
          employeeEmail: null,
        },
        children: [
          {
            departmentId: '16',
            departmentName: '行政管理部门',
            parentDepartmentId: '6',
            departmentStatus: null,
            createTime: null,
            employeeId: null,
            employeeName: null,
            employeePhone: null,
            employeeEmail: null,
          },
          {
            departmentId: '17',
            departmentName: '人才发展部门',
            parentDepartmentId: '6',
            departmentStatus: null,
            createTime: null,
            employeeId: null,
            employeeName: null,
            employeePhone: null,
            employeeEmail: null,
          },
          {
            departmentId: '18',
            departmentName: '总经理办公室',
            parentDepartmentId: '6',
            departmentStatus: null,
            createTime: null,
            employeeId: null,
            employeeName: null,
            employeePhone: null,
            employeeEmail: null,
          },
          {
            departmentId: '22',
            departmentName: '行政管理部门',
            parentDepartmentId: '6',
            departmentStatus: null,
            createTime: null,
            employeeId: null,
            employeeName: null,
            employeePhone: null,
            employeeEmail: null,
          },
          {
            departmentId: '23',
            departmentName: '总经理办公室',
            parentDepartmentId: '6',
            departmentStatus: null,
            createTime: null,
            employeeId: null,
            employeeName: null,
            employeePhone: null,
            employeeEmail: null,
          },
          {
            departmentId: '24',
            departmentName: '行政管理部门',
            parentDepartmentId: '6',
            departmentStatus: null,
            createTime: null,
            employeeId: null,
            employeeName: null,
            employeePhone: null,
            employeeEmail: null,
          },
          {
            departmentId: '25',
            departmentName: '总经理办公室',
            parentDepartmentId: '6',
            departmentStatus: null,
            createTime: null,
            employeeId: null,
            employeeName: null,
            employeePhone: null,
            employeeEmail: null,
          },
        ],
      },
      {
        departmentEmployeeDO: {
          departmentId: '7',
          departmentName: '总经理办公室',
          parentDepartmentId: '0',
          departmentStatus: '0',
          createTime: '2023-12-07 21:30:53',
          employeeId: null,
          employeeName: null,
          employeePhone: null,
          employeeEmail: null,
        },
        children: [
          {
            departmentId: '19',
            departmentName: '招聘团队',
            parentDepartmentId: '7',
            departmentStatus: null,
            createTime: null,
            employeeId: null,
            employeeName: null,
            employeePhone: null,
            employeeEmail: null,
          },
          {
            departmentId: '20',
            departmentName: '员工培训团队',
            parentDepartmentId: '7',
            departmentStatus: null,
            createTime: null,
            employeeId: null,
            employeeName: null,
            employeePhone: null,
            employeeEmail: null,
          },
          {
            departmentId: '21',
            departmentName: '薪酬福利团队',
            parentDepartmentId: '7',
            departmentStatus: null,
            createTime: null,
            employeeId: null,
            employeeName: null,
            employeePhone: null,
            employeeEmail: null,
          },
        ],
      },
      {
        departmentEmployeeDO: {
          departmentId: '51',
          departmentName: '牛逼格拉斯',
          parentDepartmentId: '0',
          departmentStatus: null,
          createTime: null,
          employeeId: '2',
          employeeName: null,
          employeePhone: null,
          employeeEmail: null,
        },
        children: [],
      },
    ],
  },
};

export const tableData = table.data.allDepartmentsList.map((item, index) => {
  let par = item.departmentEmployeeDO;
  if (item?.children && item.children.length > 0) {
    par.children = item.children;
  }
  if (par?.children && par.children.length > 0) {
    par.id = index;
    par.children.forEach((item_, index_) => {
      item_.id = index + '-' + index_;
    });
    return par;
  } else {
    return par;
  }
});

console.log(tableData);
